//
//  SetViewController.swift
//  KaMengApplication
//
//  Created by DUONIU_MAC on 2018/9/29.
//  Copyright © 2018年 DUONIU_MAC. All rights reserved.
//

import UIKit

class SetViewController: KMViewController {
    
    fileprivate let celLId = "setCell"
    fileprivate let dataArray = [evaluate,understandUs]

    override func viewDidLoad() {
        super.viewDidLoad()

        self.title = setting
        self.view.backgroundColor = UIColor.mineColor()
        createTableView()
    }
    
    //MARK: 添加子视图
    fileprivate func createTableView() {
        
        let tableView = UITableView.init(frame: .zero, style: .grouped)
        tableView.backgroundColor = UIColor.clear
        tableView.bounces = false
        tableView.delegate = self
        tableView.dataSource = self
        tableView.register(UITableViewCell.self, forCellReuseIdentifier: celLId)
        self.view.addSubview(tableView)
        
        tableView.snp.makeConstraints { (make) in
            make.edges.equalToSuperview().inset(UIEdgeInsets.zero)
        }
        
        let versionLabel = UILabel()
        //版本号
        versionLabel.text = versionNumber + "：" + (Bundle.main.infoDictionary!["CFBundleShortVersionString"] as? String)!
        versionLabel.textColor = UIColor.gray
        versionLabel.font = UIFont.systemFont(ofSize: RATIO(maxNum: 16))
        self.view.addSubview(versionLabel)
        
        versionLabel.snp.makeConstraints { (make) in
            make.bottom.equalToSuperview().offset(RATIO_H(maxNum: -30))
            make.centerX.equalToSuperview()
            make.width.greaterThanOrEqualTo(10)
            make.height.greaterThanOrEqualTo(10)
        }
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }

}

extension SetViewController : UITableViewDelegate,UITableViewDataSource {
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        
        return dataArray.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        let cell = tableView.dequeueReusableCell(withIdentifier: celLId, for: indexPath)
        cell.textLabel?.text = dataArray[indexPath.row]
        cell.accessoryType = .disclosureIndicator
        cell.selectionStyle = .none
        return cell
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        tableView.deselectRow(at: indexPath, animated: true)
        
        switch indexPath.row {
        case 0:
            //弹出透明控制器
            let likeVC = LikeViewController()
            likeVC.view.backgroundColor = UIColor.black.withAlphaComponent(0.5)
            likeVC.modalPresentationStyle = .overCurrentContext
        
            self.present(likeVC, animated: false, completion: nil)
            
            
        case 1:
            self.navigationController?.pushViewController(AboutViewController(), animated: true)
        default:
            break
        }
    }
}
